package com.sprint.questai.controller;

import com.sprint.questai.common.BaseResponse;
import com.sprint.questai.common.ResultUtils;
import com.sprint.questai.model.dto.response.ChunkResponse;
import com.sprint.questai.ocrhttp.FileService;
import com.sprint.questai.ocrhttp.OCRResponse;
import com.sprint.questai.ocrhttp.OCRServiceHttp;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/file")
public class FileController {

    private final FileService fileService;
    private final OCRServiceHttp ocrServiceHttp;

    public FileController(FileService fileService, OCRServiceHttp ocrServiceHttp) {
        this.fileService = fileService;
        this.ocrServiceHttp = ocrServiceHttp;
    }

    @PostMapping("/upload")
    public BaseResponse<List<ChunkResponse>> uploadAndProcessFile(@RequestParam("file") MultipartFile file, @RequestParam("knowledgeId") String knowledgeId) throws IOException {
        // 文件存储逻辑
        String filePath = fileService.storeFile(file);

        // OCR处理逻辑
//        String ocrResult = ocrServiceHttp.processFile(filePath);
        List<ChunkResponse> chunkResponses = ocrServiceHttp.processFileChunks(filePath, knowledgeId);

        return ResultUtils.success(chunkResponses);
    }
}
